package com.jfirer.jfireel.expression.impl.operand.basic.math.standard;

import com.jfirer.jfireel.expression.Operand;

import java.math.BigDecimal;

public class EqOperand extends MathOperand
{
    public EqOperand(String operator, Operand left, Operand right, String fragment)
    {
        super(operator, left, right, fragment);
    }

    @Override
    protected Object mathBigDecimal(Object leftValue, Object rightValue)
    {
        return new BigDecimal(leftValue.toString()).compareTo(new BigDecimal(rightValue.toString())) == 0;
    }

    @Override
    protected Boolean math(int a, int b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(int a, long b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(int a, float b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(int a, double b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(long a, int b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(long a, long b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(long a, float b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(long a, double b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(float a, int b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(float a, long b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(float a, float b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(float a, double b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(double a, int b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(double a, long b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(double a, float b)
    {
        return a == b;
    }

    @Override
    protected Boolean math(double a, double b)
    {
        return a == b;
    }

    @Override
    protected Object processOther(Object leftValue, Object rightValue)
    {
        if (leftValue == null)
        {
            return rightValue == null;
        }
        else
        {
            if (rightValue == null)
            {
                return false;
            }
            else
            {
                return leftValue.equals(rightValue);
            }
        }
    }
}
